<template>
	<view class="container" style="position: relative;">
		<u-swiper class="swiper" :height="height" :list="detail.list" :autoplay="autoplay" :effect3d="effect3d"
		:indicator-pos="indicatorPos" :mode="mode"></u-swiper>
		<view class="foot">
			<view class="title">
				{{detail.article}}
			</view>
			<view class="u-flex u-row-between">
				<view class="icon"><view @click="getLike(detail.id)" class="u-flex u-row-center"><image v-if="detail.isDz ==true" src="../../static/img/workdianzan.png" /><image v-else src="../../static/img/zan.png" /><text>赞</text></view><view class="u-flex u-row-center"><image src="../../static/img/pl.png" /><text>评论</text></view> <text @click="delComment(detail.userId)" class="u-m-l-20" v-if="detail.userId == my.id">删除</text> </view>
				<view class="icon" @click="toDetail(detail.id)"><view class="u-flex u-row-center"><image src="../../static/img/zan.png" /><text>{{detail.dzTotal}}</text></view><view class="u-flex u-row-center"><image src="../../static/img/pl.png" /><text>{{detail.plTotal}}</text></view></view>
			</view>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			id:'',
			detail:{},	
			baseUrl: this.$mConfig.baseUrl,		
			title: false,
			mode: 'round',
			indicatorPos: 'none',
			effect3d: false,
			height:200,
			autoplay:false
		};
	},
	mounted(){
		let _this = this;
		uni.getSystemInfo({
			success(res) {
				_this.height = res.windowHeight;
				console.log(res.windowHeight);
			}
		});
	},
	onLoad(options) {
		if(options){			
			if(options.id){				
				let id= options.id;
				this.id=id;
				this.getDetail();
			}
			if(options.row){
				var list = [],result= JSON.parse(decodeURIComponent(options.row));
				console.log(result);
				var imgUrls = result.imgUrl.split(',');
				for(var i in imgUrls){
					list.push({image:this.baseUrl+imgUrls[i],title: ''});
				}
				result.list = list;
				this.detail = result;
			}
		}
		this.my = this.$store.state.userInfo;
		
	},
	methods: {
		delComment(id){
			var that = this;
			uni.showModal({
				content:"删除该工作圈？",
				confirmText:"删除",
				success: (res) => {  
				if(res.confirm) {  
					that.deleteWorkCircle(id);									
				}  
			}  
			})
			
		},
		async deleteWorkCircle(id){
			let result = await this.$apis.deleteWorkCircle({id:id});	
			uni.navigateBack({
				delta:1
			})
		},
		async getDetail(){
			let result = await this.$apis.workCircleInfo({id:this.id});
			if(result.data.imgUrl.indexOf(',') == -1){
				result.data.list = [{
					image: this.baseUrl+result.data.imgUrl,
					title: ''
				}];
			}else{
				var list = [];
				var imgUrls = result.data.imgUrl.split(',');
				for(var i in imgUrls){
					list.push({image:this.baseUrl+imgUrls[i],title: ''});
				}
				result.data.list = list;
			}
			this.detail = result.data;
		},
		toDetail(id){
			this.$mRouter.push({
				route:this.$mRoutesConfig.workcircleDetail,
				query:{
					id:id
				}
			});
		},
		// 点赞
		async getLike(id) {
			let reqBody = {},userId = this.$store.state.userInfo.id;
			reqBody['userId'] = userId;
			reqBody['workId'] = id;
			let result = await this.$apis.addWorkCircleSupport(reqBody);
			if(result.code==0){
				uni.showToast({
					title:"点赞成功"
				})
			}
			this.getDetail();
		},
		// Cancel点赞
		async likeCancel(id) {
			let reqBody = {},userId = this.$store.state.userInfo.id;
			reqBody['userId'] = userId;
			reqBody['workId'] = id;
			let result = await this.$apis.deleteWorkCircleSupport(reqBody);
			if(result.code==0){
				uni.showToast({
					title:"已取消点赞"
				})
			}
			this.getDetail();
		},
	}
};
</script>

<style scoped lang="scss">
	.container {background-color: #333;}
	.container {position: relative;}
	.foot {padding:20rpx;position: fixed;bottom:0;width:100%;	background-color: rgba(0, 0, 0, 0.5);
color: #FFFFFF;
.title {font-size: 28rpx;padding-bottom:40rpx;}
		.icon {
			display: flex;
			align-items: center;
			view {margin-right: 20rpx;}
			image {width:40rpx;height:40rpx;margin-right:5rpx;margin-left:16rpx;}
		}
	}
</style>